package com.pilates.comparator;

import java.util.Comparator;
import java.util.Date;

import com.pilates.Turma;

public class TurmaComparator implements Comparator<Turma> {

	public int compare(Turma turma1, Turma turma2) {
		int retorno = 0;
		int ordinalT1 = turma1.getDiaSemana().ordinal();
		int ordinalT2 = turma2.getDiaSemana().ordinal();
		if(ordinalT1 != ordinalT2){
			retorno =  Integer.valueOf(ordinalT1).compareTo(Integer.valueOf(ordinalT2));
		}else{
			Date d1 = new Date();
			Date d2 = (Date) d1.clone();
			d1.setHours(turma1.getHorarioInicio().getHours());
			d1.setMinutes(turma1.getHorarioInicio().getMinutes());
			
			d2.setHours(turma2.getHorarioInicio().getHours());
			d2.setMinutes(turma2.getHorarioInicio().getMinutes());
			
			retorno = d1.compareTo(d2);
			
		}
			
			
		return retorno;
	}

}
